package com.chen.spring.cloud.service.coupon.controller;

import com.chen.spring.cloud.service.coupon.service.ICouponService;
import com.chen.vo.MyCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Autowired
    private ICouponService couponService;

    @RequestMapping("/myList")
    public Map<String,Object> myList(@RequestParam(value = "u_id") Integer u_id,
                                     @RequestParam(value = "limit") String limit){
        Map<String,Object> result = new HashMap<>();
        int start = 0;
        int end = 4;
        if (!StringUtils.isEmpty(limit)){
            start = Integer.parseInt(limit.split(",")[0]);
            end = Integer.parseInt(limit.split(",")[1]);
        }
        List<MyCouponVo> myCouponVoList = couponService.MyCoupons(u_id,start,end);
        int count = couponService.getMyCouponCount(u_id);


        result.put("totalcount",count);
        result.put("list",myCouponVoList);
        return result;
    }
}
